"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFormatFileSize = exports.getPackageName = exports.getLastCommitLog = void 0;
const tslib_1 = require("tslib");
// @ts-ignore
const simple_git_1 = tslib_1.__importDefault(require("simple-git"));
function getLastCommitLog(gitProject) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const git = simple_git_1.default(gitProject);
        const listLogSummary = yield git.log({ n: 1 });
        return listLogSummary.latest;
    });
}
exports.getLastCommitLog = getLastCommitLog;
function getPackageName(name) {
    if (name === '__FULL__') {
        return '整包';
    }
    else if (name === '__APP__') {
        return '主包';
    }
    else {
        return '分包';
    }
}
exports.getPackageName = getPackageName;
function getFormatFileSize(bytes) {
    if (bytes === 0) {
        return {
            size: 0,
            measure: 'Bytes',
        };
    }
    bytes *= 1024;
    const K = 1024;
    const MEASURE = ['', 'Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
    const i = Math.floor(Math.log(bytes) / Math.log(K));
    return {
        // eslint-disable-next-line no-restricted-properties
        size: parseFloat((bytes / Math.pow(K, i)).toFixed(2)),
        measure: MEASURE[i],
    };
}
exports.getFormatFileSize = getFormatFileSize;
